package com.example.base.demo.configuration;

import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/*@Component
@ConfigurationPropertiesBinding*/
public class IntegerToLocalDateTimeConverter implements Converter<Integer, LocalDateTime> {

    @Override
    public LocalDateTime convert(Integer input) {
        try {
            Date date = new SimpleDateFormat("yyyyMMdd").parse(String.valueOf(input));
            return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
}